package com.cln.salesTaxes;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Basket extends Item {

	List itemList = new ArrayList<Item>();

	public void add(IItem item) {
		this.itemList.add(item);
	}

	private void printItem(IItem item) {
		System.out.println(item.getItemName() + " : " + item.getTotal());
	}

	public BigDecimal getSalesTaxes() {
		return this.salesTaxes;
	}

	public void calculate() {
		Iterator it = itemList.iterator();
		while (it.hasNext()) {
			IItem item = (IItem) it.next();
			printItem(item);
			this.salesTaxes = item.getSalesTaxes().add(getSalesTaxes());
			this.total = item.getTotal().add(getTotal());
		}
		printTaxesAndTotal();
	}

	private void printTaxesAndTotal() {
		System.out.println("Sales Taxes: " + getSalesTaxes());
		System.out.println("Total: " + getTotal());
	}

	public BigDecimal getTotal() {
		return this.total;
	}

}
